
<?php
 //  Просмотр страниц отображения статей ______________________________________________________________
 
    $connection = connect($config);
 
    if(isset($_GET['page']) && $_GET['jurist'] == 'question_answer')
    {
        $articlres = getAllPosts($connection, "SELECT * FROM question WHERE `Apruft` = 1");         
        $allcount = count($articlres);
 
        $limit1 = 0;
        $limit2 = 4; 
    
        echo "<div class='numeration'>";
         if ($allcount > 4)
        {
            $pagestr = $allcount / 4;
            $pagestr = ceil($pagestr);
            for ($i = 1;$i <= $pagestr;$i++)
            {
            echo "<a href='/jurist/question_answer&page=".$i."'> $i </a>";
            }
        }
        echo "</div>";
        
        $getstr = $_GET['page'];
 
        for ($g = 1; $g < $getstr; $g++)
        {
            $limit1 = $limit1 + 4;
        }
        
        $countart = count($articlres);
        $articlres = getAllPosts($connection, "SELECT * FROM question WHERE `Apruft` = 1 
                                            LIMIT $limit1 , $limit2");
 
        for ($i = 0;$i < $countart; $i++)
        {
    
            $s1 = mb_substr($articlres[$i][Answer],0,1475,'utf-8');
            $s2 =  strlen($articlres[$i][Answer]);
        
            echo "<div class='blog'>";
            echo "<h2>Вопрос:</h2>","<p>".$articlres[$i][Question]."</p>";
            echo "<h2>Ответ:</h2>","<p>".$s1;
            if($s2 > 1475) echo ".....";
            echo "</p>";
        
        if($s2 > 1475) echo "<span class='articleright'><a href='/jurist/question_answer&answer=".$articlres[$i][QuestionID]."'>Читать дальше ></a></span>";
        echo "</div>";
        

    
    }
} 
 
// Просмотр самоко вопроса __________________________________________

    if(isset($_GET['answer']))
    {
        $getID = array('id' => $_GET['answer']);
        $articlres = query("SELECT * FROM question WHERE `Apruft` = :id", $getID, $connection);

        echo "<div class='blog'>";
        echo "<h2>Вопрос:</h2>","<p>".$articlres[0][Question]."</p>";
        echo "<h2>Ответ:</h2>","<p>".$articlres[0][Answer]."</p>";
        echo "</div>";    
    }



 
	  
?>